package com.geektime.hello.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.RandomUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: DRevelation
 * @Date: 2021/3/26 15:39
 */
@RestController
@RequestMapping("saToken")
public class SaTokenController {

    @GetMapping("login")
    public String login() {
        String loginId = RandomUtil.randomNumbers(11);
        StpUtil.setLoginId(loginId);
        return "登录成功，loginId=" + loginId;
    }

    @GetMapping("/index")
    public String index() {
        boolean isLogin = StpUtil.isLogin();
        if (isLogin) {
            return "Hello Sa-Token, loginId=" + StpUtil.getLoginId();
        } else {
            return "No Login";
        }
    }

}
